<template>
	<div style="height:100%">
		<cl-crud @load="onLoad">
			<template #table-column-status="{scope}">
				<el-tag v-if="scope.row.status == 1" type="success">启用</el-tag>
				<el-tag type="info" v-else>禁用</el-tag>
			</template>
		</cl-crud>
	</div>
</template>

<script>
import subsidiesToday from '../goodsMenagement/components/subsidiesToday';
export default {
	data() {
		return {};
	},

	mounted() {},

	methods: {
		onLoad({ ctx, app }) {
			this.crud = app;
			ctx.service(this.$service.integralMall.bigRedPacket)
				.set('table', {
					columns: [
						{
							prop: 'period',
							label: '周期(天)',
							align: 'center'
						},
						{
							prop: 'identification',
							label: '大额标识(第几天)',
							align: 'center'
						},
						{
							prop: 'goldAmount',
							label: '膨胀金币',
							align: 'center'
						},
						{
							prop: 'refreshTime',
							label: '刷新时间',
							align: 'center'
						},
						{
							prop: 'status',
							label: '状态',
							align: 'center'
						}
					],
					op: {
						layout: ['edit', 'delete']
					}
				})
				.set('upsert', {
					props: {
						labelWidth: '112px',
						with: '800px'
					},
					items: [
						{
							prop: 'period',
							label: '周期(天)',
							span: 13,
							value: 1,
							component: {
								name: 'el-input-number',
								attrs: {
									min: 1,
									max: 100
								}
							},
							rules: [
								{
									required: true,
									message: '请输入周期',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'identification',
							label: '大额标识(第几天)',
							span: 13,
							value: 1,
							component: {
								name: 'el-input-number',
								attrs: {
									min: 1,
									max: 100
								}
							},
							rules: [
								{
									required: true,
									message: '请输入大额标识',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'goldAmount',
							label: '膨胀金币',
							component: {
								name: 'goldAmount-c',
								components: {
									subsidiesToday
								},
								methods: {
									input(val) {
										this.$emit('input', val);
									}
								},
								props: {
									value: [String, Number]
								},
								render() {
									return (
										<subsidiesToday
											value={this.value}
											addLimti="5"
											onInput={this.input}></subsidiesToday>
									);
								}
							},
							rules: [
								{
									required: true,
									message: '请选择渠道',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'refreshTime',
							label: '刷新时间',
							span: 13,
							component: {
								name: 'el-select',
								options: []
							},
							rules: [
								{
									required: true,
									message: '请选择刷新时间',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'status',
							label: '状态',
							span: 13,
							value: 2,
							component: {
								name: 'el-radio-group',

								options: [
									{
										label: '启用',
										value: 1
									},
									{
										label: '禁用',
										value: 2
									}
								]
							}
						}
					]
				})
				.set('layout', [
					['refresh-btn', 'add-btn'],
					['data-table'],
					['flex1', 'pagination']
				])
				.on('open', () => {
					let timeH = [];
					for (let i = 0; i <= 24; i++) {
						timeH.push({
							label: i,
							value: i
						});
					}
					app.setData('upsert.items[prop:refreshTime].component.options', timeH);
				})
				.on('submit', async (isEdit, data, { next }) => {
					next({
						...data
					});
				})
				.done();
			app.refresh();
		}
	}
};
</script>
<style lang="scss" scoped></style>
